/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Bean;

import Database.CommentData;
import Database.PostData;
import Entity.Comment;
import Entity.Post;
import bussiness.Login;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author cuong_000
 */
public class PostManager {
    private ArrayList<Post> postList;
    private ArrayList<Comment> CmtList;

    public PostManager() {
        this.postList = getListPosts(Login.UserStatic.getId());
        this.CmtList = getListComments(Login.UserStatic.getId());
    }
    
    
    
    public ArrayList<Post> getListPosts(int userId){
        try {
            ArrayList<Post> listPost = PostData.getAllPost(userId);
            return listPost;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PostManager.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (SQLException ex) {
            Logger.getLogger(PostManager.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
    
    public ArrayList<Comment> getListComments(int postId){
        try {
            ArrayList<Comment> listCmt = CommentData.getCommentById(postId);
            return listCmt;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PostManager.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (SQLException ex) {
            Logger.getLogger(PostManager.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
    
}
